class Shape {
    public void draw() {
        System.out.println("画图形");
    }
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("画矩形");
    }
}
class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("画圆");
    }
}
class Flower extends Shape {
    @Override
    public void draw() {
        System.out.println("画❀");
    }
}
public class DuoTai2 {
    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void drawMap2() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        //cycle rect cycle rect flower
        String[] shapes = {"cycle", "rect", "cycle","rect","flower"};
        for (String s : shapes) {
            if (s.equals("cycle")) {
                cycle.draw();
            }else if (s.equals("rect")) {
                rect.draw();
            }else {
                flower.draw();
            }
        }
    }
    public static void drawMap() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shape[] shapes = {cycle,rect,cycle,rect,flower};
        //发生了向上转型
        //int[] array = {1,2,3,45};

        for(Shape shape : shapes) {
            shape.draw();
        }
    }
    public static void drawMap3() {
        Shape rect = new Rect();
        Shape cycle = new Cycle();
        Shape flower = new Flower();

        Shape[] shapes = {cycle,rect,cycle,rect,flower};
        //发生了向上转型
        //int[] array = {1,2,3,45};

        for(Shape shape : shapes) {
            shape.draw();
        }
    }

    public static void main(String[] args) {
        drawMap();
        //drawMap2();
    }
    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();

        drawMap(rect);
        drawMap(cycle);
        drawMap(new Flower());
    }
}
